package fr.umlv.m2.jee.portailEtudiant.persistence;

import org.hibernate.annotations.Type;
import org.joda.time.DateTime;

import javax.persistence.*;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: soufiane
 * Date: 10/02/11
 * Time: 16:30
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "COURSE")
public class Course implements Serializable {

    @Id
    @GeneratedValue
    private long idCourse;

    @Column(name ="COURSE_NAME", nullable = false)
    private String name;

    @Column ( name = "COURSE_EXAM_DATE")
    @Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
    private DateTime examenDate;

    @OneToMany (mappedBy = "course", fetch = FetchType.LAZY, cascade =  CascadeType.ALL)
    private List< Td > tds =  new LinkedList< Td >();

    @OneToMany (mappedBy = "course", fetch = FetchType.LAZY, cascade =  CascadeType.ALL)
    private List< Tutorial > tutorials =  new LinkedList< Tutorial >();

    @OneToMany (mappedBy = "course", fetch = FetchType.LAZY, cascade =  CascadeType.ALL)
    private List< Tp > tps =  new LinkedList< Tp >();

    @OneToMany (mappedBy = "course", fetch = FetchType.LAZY, cascade =  CascadeType.ALL)
    private List<CourseDocument> documentList =  new LinkedList<CourseDocument>();

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "idFormation")
    private Formation formation;


    public long getIdCourse() {
        return idCourse;
    }

    public String getName() {
        return name;
    }

    public List< Td > getTds() {
        return tds;
    }

    public List< Tp > getTps() {
        return tps;
    }

    public List< Tutorial > getTutorials() {
        return tutorials;
    }

    public DateTime getExamenDate() {
        return examenDate;
    }

    public Formation getFormation() {
        return formation;
    }

    public void setIdCourse(long newIdCourse) {
        this.idCourse = newIdCourse;
    }

    public void setName(String newName) {
        this.name = newName;
    }

    public void setExamenDate(DateTime newExamenDate) {
        this.examenDate = newExamenDate;
    }

    public void setFormation(Formation newformation) {
        this.formation = newformation;
    }

    public void add(Td addon) {
        tds.add(0, addon);
    }

     public void add(Tp addon) {
        tps.add(0, addon);
    }

     public void add(Tutorial addon) {
        tutorials.add(0, addon);
    }

    public void add(CourseDocument addon) {
        documentList.add(0, addon);
    }

    public void setTds(List< Td > newListTds) {
        this.tds = newListTds;
    }

    public void setTps(List< Tp > newListTps) {
        this.tps = newListTps;
    }

    public void setTutorials(List< Tutorial > newListTuto) {
        this.tutorials = newListTuto;
    }

    public List<CourseDocument> getDocumentList() {
        return documentList;
    }

    public void setDocumentList(List<CourseDocument> documentList) {
        this.documentList = documentList;
    }
}
